package com.hhs.storage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ResponseBean;
import com.hhs.storage.bean.ResponseBeanPage;
import com.hhs.storage.bean.WorkOvertime;
import com.hhs.storage.service.OvertimeApprovalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chx
 * @since 2024-01-26
 */
@RestController
@RequestMapping("/overtimeApproval")
@ApiSupport(order = 1)
@Api(tags = "加班审批")
public class OvertimeApprovalController {

    @Resource
    private OvertimeApprovalService overtimeApprovalService;

    @RequestMapping("table")
    @ApiOperation(value = "获取数据",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "name", value = "用户名", required =
                    true, paramType = "query"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "approvalStatus", value = "审批状态 null-全部 0-审批中 1-已审批 2-驳回", required =
                    true, paramType = "query"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "page", value = "页码", required =
                    true, paramType = "query"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "size", value = "每页条数", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBeanPage<WorkOvertime> getAll(@ApiIgnore WorkOvertime workOvertime, @ApiIgnore InputParam inputParam) {
        Map<String, Object> map = overtimeApprovalService.getAll(workOvertime, inputParam);
        ResponseBeanPage<WorkOvertime> rb = ResponseBeanPage.getInstance();
        rb.setCode((Integer) map.get("code"));
        rb.setRows((List<WorkOvertime>) map.get("rows"));
        rb.setTotal((Long) map.get("total"));
        return rb;
    }

    @PostMapping("approval")
    @ApiOperation(value = "审批",
            httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, name = "approvalStatus", value = "审批状态 0-审批中 1-已审批 2-驳回", required =
                    true, paramType = "query"),
            @ApiImplicitParam(dataTypeClass = String.class, name = "approvalOpinion", value = "审批意见", required =
                    true, paramType = "query"),
    })
    @ApiOperationSupport(order = 1)
    public ResponseBean<WorkOvertime> approval(@ApiIgnore @RequestBody WorkOvertime workOvertime) {
        Map<String, Object> map = overtimeApprovalService.approval(workOvertime);
        ResponseBean<WorkOvertime> rb = ResponseBean.getInstance();
        rb.setCode((Integer) map.get("code"));
        rb.setData((WorkOvertime) map.get("data"));
        return rb;
    }

}

